package graph.mcg;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.emf.ecore.EOperation;
import org.eclipse.emf.ecore.impl.EClassImpl;
import org.eclipse.emf.ecore.impl.EOperationImpl;
import org.eclipse.ocl.ecore.Constraint;

public class ConstraintInfo {

	private Constraint constraint;
	private String conditionname;
	private String constraintType;
	private String className;
	private String methodName;
	private String returnType;

	private List<String[]> attributeList;
	private List<String[]> parameterList;

	public ConstraintInfo() {

	}

	public ConstraintInfo(Constraint con) {
		this.constraint = con;
		
		// Constraint type: invariant, precondition, postcondition
		this.constraintType = constraint.getStereotype(); 
		
		// Constraint name
		conditionname = con.getName();
		
		// Class name
		this.className = constraint.getSpecification().getContextVariable().getType().getName();
		
		// Method name
		if (constraint.getConstrainedElements().get(0).getClass().equals(EClassImpl.class)) {
			this.methodName = ((EClassImpl) constraint.getConstrainedElements().get(0)).getName();
		} else if (constraint.getConstrainedElements().get(0).getClass().equals(EOperationImpl.class)) {
			this.methodName = ((EOperationImpl) constraint.getConstrainedElements().get(0)).getName();
		}

		// Result type
		if (constraint.getSpecification().getResultVariable() != null) {
			this.returnType = constraint.getSpecification().getResultVariable().getType().getName();
		}
		
	}

	public String getConditionname() {
		return conditionname;
	}

	public void setConditionname(String conditionname) {
		this.conditionname = conditionname;
	}

	public void setClassName(String className) {
		this.className = className;
	}

	public void setMethodName(String methodName) {
		this.methodName = methodName;
	}

	public Constraint getConstraint() {
		return constraint;
	}

	public String getConstraintType() {
		return constraintType;
	}

	public String getClassName() {
		return className;
	}

	public String getMethodName() {
		return methodName;
	}

	public List<String[]> getAttributeList() {
		return attributeList;
	}

	public void setAttributeList(List<String[]> attributeList) {
		this.attributeList = attributeList;
	}

	public List<String[]> getParameterList() {
		return parameterList;
	}

	public void setParameterList(List<String[]> parameterList) {
		this.parameterList = parameterList;
	}

	public String getReturnType() {
		return returnType;
	}

}
